package com.shuiqinling.ww.android.Util;

import android.app.Activity;
import android.app.ProgressDialog;
import android.widget.Toast;

public class UIHelper {
	public static ProgressDialog m_pDialog;

	private static Activity act;

	private static int currentToastLevel = 1;

	public static void Init(Activity activity) {
		UIHelper.act = activity;
	}

	public static void ShowWaitDialog() {

		act.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				if (m_pDialog == null) {
					// 创建ProgressDialog对象
					m_pDialog = new ProgressDialog(act);

					// 设置进度条风格，风格为圆形，旋转的
					m_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

					// 设置ProgressDialog 提示信息
					m_pDialog.setMessage("请稍等。。。");

					// 设置ProgressDialog 的进度条是否不明确
					m_pDialog.setIndeterminate(false);

					// 设置ProgressDialog 是否可以按退回按键取消
					m_pDialog.setCancelable(false);
				}
				m_pDialog.show();
			}
		});
	}

	public static void HideWaitDialog() {
		act.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				if (m_pDialog != null) {
					m_pDialog.hide();
				}
			}
		});
	}

	public static void ShowToast(final String msg) {
		ShowToast(msg, 0);
	}

	public static void ShowToast(final String msg, int level) {
		if (level >= currentToastLevel) {
			act.runOnUiThread(new Runnable() {

				@Override
				public void run() {
					Toast.makeText(act, msg, Toast.LENGTH_LONG).show();
				}
			});
		}
	}
}
